import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.List;

/**
 * @file FileList.java
 * @author zemo
 * @mail zemochen@gmail.com
 * @data 2014年5月5日 下午7:53:49
 * @description: 文件列表
 */
public class FileBrowser extends List implements CommandListener{

		
	private InfoCanvas infoCanvas;
	//主页面按钮
	private Command enterCommand = new Command("阅读",Command.OK,1);;//进入阅读
	private Command returnCommand = new Command("返回",Command.BACK,1);//返回
	private Display display;
	private DisplayCanvas midlet;
	
	public FileBrowser() {
		super("文件列表",Choice.IMPLICIT);
		append("小说1",null);
		append("小说2",null);
		append("小说3",null);
		
		addCommand(enterCommand);
		addCommand(returnCommand);
		setCommandListener(this);
	}

	public void commandAction(Command c, Displayable d) {
		if(c == returnCommand){//返回
			System.out.println(returnCommand.getLabel());
		}else if(c == enterCommand){//进入阅读
			int index = this.getSelectedIndex()+1;
			ReadFile readFile = new ReadFile();
			String string=readFile.read(index+"");
			infoCanvas = new InfoCanvas(midlet,display,string);
			display.setCurrent(infoCanvas);
		}
	}
	

}
